package com.xiaoming.coupon.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * 优惠券分类
 *
 * @author xiaoming
 * @Date 2020/5/12
 * @blame Android Team
 */
@Getter
@AllArgsConstructor
public enum  CouponCategory {

    MANJIAN("满减券", "001"),
    ZHEKOU("折扣券", "002"),
    LIJIAN("立减券", "003");

    /**
     * 优惠券描述（）分类
     */
    private final String description;
    /**
     * 优惠券分类编码
     */
    private final String code;

    /**
     * 根据code获取对应枚举
     * @param code
     * @return
     */
    public static CouponCategory of(String code){
        Objects.requireNonNull(code);
        return Stream.of(values())
                .filter(bean -> bean.code.equals(code))
                .findAny()
                .orElseThrow(() -> new IllegalArgumentException(code + " not exists"));
    }
}
